package com.west_traveler.utils;

import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Shader;

import com.squareup.picasso.Transformation;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.SimpleFormatter;

/**
 * Description: 获得圆形图片
 * Date:2016年12月06日23:42
 *
 * @author: 刘悦.
 */

public class GetCirclePhoto implements Transformation {
    @Override
    public Bitmap transform(Bitmap source) {
        Bitmap bitmap = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));//拉伸
        new Canvas(bitmap).drawCircle(source.getWidth() / 2, source.getHeight() / 2, source.getWidth() / 2, paint);
//        source.recycle();
        if (source != null && !source.isRecycled()) {
            source = null;
        }
        return bitmap;
    }

    @Override
    public String key() {
        return "circle";
    }
}
